package com.mydemo.admin.controller;

import com.mydemo.admin.service.ISysOperLogService;
import com.mydemo.common.pojo.RespResult;
import com.mydemo.common.pojo.SysOperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志控制器
 *
 * @author Last_Island
 * @version 1.0
 */
@RestController
@RequestMapping("/operLog")
public class SysOperLogController extends BaseController {

    @Autowired
    private ISysOperLogService sysOperLogService;

    /**
     * 查询操作日志列表
     * @param log 查询条件
     * @return
     */
    @PreAuthorize("@authz.decide('system:operLog:list')")
    @GetMapping("/list")
    public RespResult getList(SysOperLog log) {
        startPage();
        List<SysOperLog> list = sysOperLogService.getList(log);
        return getTabData(list);
    }

    /**
     * 查询操作日志详情
     * @param id
     * @return
     */
    @PreAuthorize("@authz.decide('system:operLog:get')")
    @GetMapping("/{id}")
    public RespResult getOperLogById(@PathVariable("id") Long id) {
        SysOperLog log = sysOperLogService.getOperLogById(id);
        return RespResult.defaultSuccess(log);
    }

    /**
     * 删除操作日志
     *
     * @param ids
     * @return
     */
    @PreAuthorize("@authz.decide('system:operLog:del')")
    @DeleteMapping("/{ids}")
    public RespResult delOperLog(@PathVariable("ids") Long[] ids) {
        return sysOperLogService.delete(ids) ? RespResult.defaultSuccess() : RespResult.defaultError();
    }
}
